package com.example.victory.service;

import com.alibaba.fastjson.JSONObject;
import com.example.victory.swagger.handler.AppCustomerOverallAccountApiDelegate;
import com.example.victory.swagger.model.*;
import com.cgws.fintech.inner.business.customer.utils.JsonUtils;
import com.cgws.fintech.sdk.api.inner.crmapi.model.ApiRequesFsdp;
import com.cgws.fintech.sdk.api.inner.crmapi.model.ApiRequesFsdpData;
import com.cgws.fintech.sdk.api.inner.crmapi.model.ApiResponseFsdp;
import com.example.victory.common.web.ServiceHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class AppCustomerOverallAccountService implements AppCustomerOverallAccountApiDelegate{

    @Autowired
    private InnerCustOverallAccountFsdpService innerCustOverallAccountFsdpService;

    @Override
    public ResponseEntity<ApiResponseGetCustomerOverallAccount> getCustomerOverallAccount(ApiRequestCustomerId param) {
        ApiRequestCustomerIdData data = param.getData();
        ServiceHelper.checkDataNotNull(data, "data");
        String customerId = data.getCustomerId();
        ServiceHelper.checkDataNotNull(customerId, "data.customerId");

        JSONObject jsonObject=new JSONObject();
        jsonObject.put("customerId", customerId);
        ResponseEntity<ApiResponseFsdp> fsdpResponseEntity = innerCustOverallAccountFsdpService.getAccountAllInfo(new ApiRequesFsdp().data(new ApiRequesFsdpData().params(jsonObject.toJSONString())));
        ApiResponseGetCustomerOverallAccountData resultEntity = JsonUtils.getResultEntity(fsdpResponseEntity, ApiResponseGetCustomerOverallAccountData.class);
        return ResponseEntity.ok(new ApiResponseGetCustomerOverallAccount().data(resultEntity));
    }

}
